import { fileURLToPath, URL } from 'node:url'
import path from 'path'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import VueRouter from 'unplugin-vue-router/vite'
import AutoImport from 'unplugin-auto-import/vite'
import { VueRouterAutoImports } from 'unplugin-vue-router'
import Components from 'unplugin-vue-components/vite'
import { AntDesignVueResolver } from 'unplugin-vue-components/resolvers'

const pathSrc = path.resolve(__dirname, 'src')
// https://vitejs.dev/config/
export default defineConfig({
  base: './',
  plugins: [
    VueRouter({
      routesFolder: 'src/pages',
      routeBlockLang: 'yaml'
    }),
    vue(),
    vueJsx(),
    AutoImport({
      eslintrc: {
        enabled: true
      },
      resolvers: [],
      imports: ['vue', VueRouterAutoImports]
    }),
    Components({
      resolvers: [
        AntDesignVueResolver({
          importStyle: false // css in js
        })
      ],

      dts: path.resolve(pathSrc, 'components.d.ts')
    })
  ],
  server: {
    proxy: {
      '/gc': {
        target: 'https://general.guandata.com',
        changeOrigin: true
        // rewrite: (path) => path.replace(/^\/api/, '')
      }
    }
  },
  resolve: {
    alias: {
      '@': path.resolve(pathSrc)
    }
  }
})
